﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;

namespace Admin.WorkFlow.FormTable.TaskBook
{
    public partial class TaskBook_ReadOnly : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].ToString() != "")
                {
                    int id = ChinaSoft.Common.Input.SetInt(Request.Params["id"]);
                    BindInfo(id);
                    BindDepartMent(id);
                }
            }
        }
        private void BindInfo(int id)
        {
            ChinaSoft.BLL.Common.Bind bllBind = new ChinaSoft.BLL.Common.Bind();
            DataSet ds=bllBind.GetDataSet("*", "V_TaskBookLook", "TaskBookId="+id);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                DataRow dr = ds.Tables[0].Rows[0];
                lblMainNumber.Text = dr["MainNumber"].ToString();
                lblSubNumber.Text = dr["SubNumber"].ToString();
                lblIssueTime.Text = Convert.ToDateTime(dr["IssueTime"].ToString()).ToShortDateString();
                lblProjectName.Text = dr["ProjectName"].ToString();
                lblCustomer.Text = dr["Customer"].ToString();
                lblProjectType.Text = dr["ProjectType"].ToString()=="0"?"A":"B";
                string issue = string.Empty;
                switch (dr["According"].ToString())
                {
                    case "0":
                        issue = "委托";
                        break;
                    case "1":
                        issue = "非委托";
                        break;
                }
                lblIssue.Text = issue;
                lblUnderTakeDepartment.Text = dr["DepartMentName"].ToString();
                lblContractMoney.Text = dr["ContractMoney"].ToString();

                #region 项目阶段
                string stage=string.Empty;
                switch (dr["Stage"].ToString())
                {
                    case "1":
                        stage = "项目建议书";
                        break;
                    case "2":
                        stage = "预可";
                        break;
                    case "3":
                        stage = "工可";
                        break;
                    case "4":
                        stage = "项目申请报告";
                        break;
                    case "5":
                        stage = "方案设计";
                        break;
                    case "6":
                        stage = "初步设计";
                        break;
                    case "7":
                        stage = "施工图设计";
                        break;
                    case "8":
                        stage = "规划咨询";
                        break;
                    case "9":
                        stage = "试验检测";
                        break;
                    case "10":
                        stage = "科研";
                        break;
                }
                #endregion
                lblStage.Text = stage;
                lblEndTime.Text = Convert.ToDateTime(dr["EndTime"]).ToShortDateString();
                lblEndTimeDescription.Text = dr["EndTimeDescription"].ToString();
                lblDescription.Text = dr["Description"].ToString();

                lblJingBanMan.Text = GetProjectUserName(ChinaSoft.Common.Input.SetInt(dr["JingBanId"]));
                lblMakeDevelop.Text = GetProjectUserName(ChinaSoft.Common.Input.SetInt(dr["MakeDevelopId"]));
                lblEngieer.Text = GetProjectUserName(ChinaSoft.Common.Input.SetInt(dr["EngineerId"]));
                lblYuanZhang.Text = GetProjectUserName(ChinaSoft.Common.Input.SetInt(dr["SubDeanId"]));
            }
        }
        private string GetProjectUserName(int UserId)
        {
            string strUserName = string.Empty;
            ChinaSoft.BLL.BLL_tb_MidSoft_Users bllUsers = new ChinaSoft.BLL.BLL_tb_MidSoft_Users();
            ChinaSoft.Model.Model_tb_MidSoft_Users modelUsers = bllUsers.GetModel(UserId);
            if (modelUsers != null)
            {
                strUserName = modelUsers.UserName;   
            }
            return strUserName;
        }
        private void BindDepartMent(int TaskBookId)
        {
            ChinaSoft.BLL.Common.Bind bllBind = new ChinaSoft.BLL.Common.Bind();
            #region 主办部门
            DataSet ds=bllBind.GetDataSet("*", "V_XieBanDepartMent", "DepartMentType=0 and TaskBookId="+TaskBookId);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                lblMainDepartMent.Text = ds.Tables[0].Rows[0]["DepartMentName"].ToString();
                lblMainMoney.Text = ds.Tables[0].Rows[0]["OutPut"].ToString();
                int MainXieBanId = Convert.ToInt32(ds.Tables[0].Rows[0]["XieBanId"]);
                lblMainMan.Text = GetUserName(TaskBookId, MainXieBanId);
            }
            #endregion
            #region 协办部门
            ds=bllBind.GetDataSet("*", "V_XieBanDepartMent", "DepartMentType=1 and TaskBookId="+TaskBookId);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                GridView1.DataSource = ds;
                GridView1.DataBind();
            }
            #endregion 
        }

        private string GetUserName(int TaskBookId, int XieBanId)
        {
            string strUserName = string.Empty;
            ChinaSoft.BLL.Common.Bind bllBind = new ChinaSoft.BLL.Common.Bind();
            DataSet ds=bllBind.GetDataSet("*", "V_SubContractUserLook", "TaskBookId=" + TaskBookId + " and  XieBanId=" + XieBanId);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
			    {
                    strUserName += ds.Tables[0].Rows[i]["UserName"].ToString()+"  ";
			    }
            }
            return strUserName;
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ChinaSoft.BLL.Common.Bind bllBind = new ChinaSoft.BLL.Common.Bind();
                string XieBanId = GridView1.DataKeys[e.Row.RowIndex][0].ToString();
                DataSet ds = bllBind.GetDataSet("*", "V_SubContractUserLook", " XieBanId=" + XieBanId + " and TaskBookId="+ChinaSoft.Common.Input.SetInt(Request.Params["id"]));
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    Label lblMan = e.Row.FindControl("lblProjectMan") as Label;
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        lblMan.Text += ds.Tables[0].Rows[i]["UserName"].ToString() + ",";
                    }
                }
            }
        }
    }
}